import request from '@/utils/http'

// 获取用户列表
export function fetchGetUserList(params: Api.SystemManage.UserSearchParams) {
  return request.get<Api.SystemManage.UserList>({
    url: '/system/users',
    params
  })
}

// 新增用户
export function fetchAddUser(data: Partial<Api.SystemManage.User>) {
  return request.post<Api.Common.commonResponse<null>>({
    url: '/system/users',
    data
  })
}
// 更新用户
export function fetchUpdateUser(id: number, data: Partial<Api.SystemManage.User>) {
  return request.put<Api.Common.commonResponse<null>>({
    url: `/system/users/${id}`,
    data
  })
}

// 删除用户
export function fetchDeleteUser(id: number) {
  return request.del<Api.Common.commonResponse<null>>({
    url: `/system/users/${id}`
  })
}
// 根据id获取用户信息
export function fetchGetUserById(id: number) {
  return request.get<Api.Common.commonResponse<Api.SystemManage.User>>({
    url: `/system/users/${id}`
  })
}

// 获取角色列表
export function fetchGetRoleList(params: Api.SystemManage.RoleSearchParams) {
  return request.get<Api.SystemManage.RoleList>({
    url: '/api/role/list',
    params
  })
}

// 获取菜单列表
export function fetchGetMenuList() {
  return request.get<Api.SystemManage.MenuListResponse>({
    url: '/account/menus'
  })
}

// 获取角色列表
export function fetchGetRoleAllList() {
  return request.get<Api.SystemManage.RoleListItemResponse>({
    url: '/system/roles'
  })
}

// 修改用户密码
export function fetchUpdateUserPassword(id: number, password: string) {
  return request.post<Api.Common.commonResponse<null>>({
    url: `/system/users/${id}/password`,
    data: { password }
  })
}
